import 'dart:js';
import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:todo_list/i10n/localization_intl.dart';
import 'package:todo_list/model/account_page_model.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';


class AccountPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final primaryColor = Theme.of(context).primaryColor;
    final primaryColorLight = Theme.of(context).primaryColorLight;
    final size = MediaQuery.of(context).size;

    final model = Provider.of<AccountPageModel>(context)..setContext(context);

    return WillPopScope(
      onWillPop: () {
        model.isExisting = true;
        model.refresh();
        return Future.value(true);
      },
      child: Stack(
        children: <Widget>[
          Container(
              width: size.width,
              height: size.height,
              child: SvgPicture.asset(
                "svgs/bg.svg",
                fit: BoxFit.cover,
              )),
          model.isExisting
              ? Container()
              : BackdropFilter(
                  filter: ImageFilter.blur(sigmaX: 3, sigmaY: 3),
                  child: Container(
                    width: size.width,
                    height: size.height,
                    color: primaryColor.withOpacity(0.1),
                  ),
                ),
          GestureDetector(
            //    onTap: model.logic.onBackgroundTap,
            child: Scaffold(
              backgroundColor: Colors.transparent,
              appBar: AppBar(
                title: Text(IntlLocalizations.of(context).myAccount),
                backgroundColor: Colors.transparent,
              ),
              body: Container(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "用户名",
                          ),
                          Chip(
                            label: Text(model.userName.toString()),
                          ),
                          Container(
                            child: Text(
                              "占位占位占位",
                              style: TextStyle(color: Colors.white),
                            ),
                          )
                        ],
                      ),
                      decoration: BoxDecoration(color: Colors.white),
                      margin: EdgeInsets.all(1.0),
                    ),
                    Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "账号",
                          ),
                          Chip(
                            label: Text(model.emailAccount.toString()),
                          ),
                          Container(
                            child: Text(
                              "占位占位占位",
                              style: TextStyle(color: Colors.white),
                            ),
                          )
                        ],
                      ),
                      decoration: BoxDecoration(color: Colors.white),
                      margin: EdgeInsets.all(1.0),
                    ),
                    Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "VIP等级",
                          ),
                          Chip(
                            label: Text(model.vip.toString()),
                            deleteIcon: Icon(Icons.arrow_upward),
                          ),
                          FlatButton(
                            color: primaryColor,
                            highlightColor: primaryColorLight,
                            colorBrightness: Brightness.dark,
                            splashColor: Colors.grey,
                            child: Text("升级"),
                            shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(20.0)),
                            onPressed: () {},
                          ),
                        ],
                      ),
                      decoration: BoxDecoration(color: Colors.white),
                      margin: EdgeInsets.all(1.0),
                    ),
                    Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "积分",
                          ),
                          Chip(
                            label: Text(model.contri.toString()),
                          ),
                          FlatButton(
                            color: primaryColor,
                            highlightColor: primaryColorLight,
                            colorBrightness: Brightness.dark,
                            splashColor: Colors.grey,
                            child: Text("签到"),
                            shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(20.0)),
                            onPressed: () {
                              model.onIncScore();
                              // showDialog(context: context, builder: (context){
                              //   return AlertDialog(
                              //     title: Text("签到成功，积分+1"),
                              //   );
                              // });
                            },
                          ),
                        ],
                      ),
                      decoration: BoxDecoration(color: Colors.white),
                      margin: EdgeInsets.all(1.0),
                    ),
                    Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "金币",
                          ),
                          Chip(
                            label: Text(model.coin.toString()),
                          ),
                          Container(
                            child: Text(
                              "占位占位占位",
                              style: TextStyle(color: Colors.white),
                            ),
                          )
                        ],
                      ),
                      decoration: BoxDecoration(color: Colors.white),
                      margin: EdgeInsets.all(1.0),
                    ),
                    Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "贡献：",
                          ),
                          Chip(
                            label: Text(model.contri.toString()),
                          ),
                          FlatButton(
                            color: primaryColor,
                            highlightColor: primaryColorLight,
                            colorBrightness: Brightness.dark,
                            splashColor: Colors.grey,
                            child: Text("充值"),
                            shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(20.0)),
                            onPressed: () {

                              showDialog(context: context, builder: (context){
                                  return AlertDialog(
                                    title: Text("充值（1元=10金币 + 1积分）"),
                                    content: Image.asset("images/zsm.jpg"),
                                  );
                              });
                            },
                          ),
                        ],
                      ),
                      decoration: BoxDecoration(color: Colors.white),
                      margin: EdgeInsets.all(1.0),
                    ),

                    Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "被绑定号：",
                          ),
                          Chip(
                            label: Text(model.invitecode.toString() + "  vip1"),
                            deleteIcon: Icon(Icons.arrow_upward),
                          ),
                          Container(
                            child: Text(
                              "占位占位占位",
                              style: TextStyle(color: Colors.white),
                            ),
                          )
                        ],
                      ),
                      decoration: BoxDecoration(color: Colors.white),
                      margin: EdgeInsets.all(1.0),
                    ),
                    Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "绑定号：",
                          ),
                          Chip(
                            label: Text(model.subCounts.toString()+"人"),
                            deleteIcon: Icon(Icons.details),
                          ),
                          FlatButton(
                            color: primaryColor,
                            highlightColor: primaryColorLight,
                            colorBrightness: Brightness.dark,
                            splashColor: Colors.grey,
                            child: Text("详情"),
                            shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(20.0)),
                            onPressed: () {},
                          ),
                        ],
                      ),
                      decoration: BoxDecoration(color: Colors.white),
                      margin: EdgeInsets.all(1.0),
                      alignment: Alignment.center,
                    ),
                    Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            "我的邀请码：",
                          ),
                          Chip(
                            label: Text(model.myic.toString()),
                            deleteIcon: Icon(Icons.details),
                          ),
                          Chip(
                            label: SelectableText("邀请链接： https://2020cn.cn/#/register?"+model.myic.toString()),
                            deleteIcon: Icon(Icons.details),
                          ),

                        ],
                      ),
                      decoration: BoxDecoration(color: Colors.white),
                      margin: EdgeInsets.all(1.0),
                      alignment: Alignment.center,
                    ),

                    FlatButton(
                      color: primaryColor,
                      highlightColor: primaryColorLight,
                      colorBrightness: Brightness.dark,
                      splashColor: Colors.grey,
                      child: Text(IntlLocalizations.of(context).resetPassword),
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(20.0)),
                      onPressed: model.logic.onResetPasswordPressed,
                    ),
                    FlatButton(
                      color: primaryColor,
                      highlightColor: primaryColorLight,
                      colorBrightness: Brightness.dark,
                      splashColor: Colors.grey,
                      child: Text(IntlLocalizations.of(context).logout),
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(20.0)),
                      onPressed: model.logic.onLogoutPressed,
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

}
